package com.typhoon.spring_redis.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.typhoon.spring_redis.dao.UserDao;
import com.typhoon.spring_redis.dto.UserDto;
import com.typhoon.spring_redis.entity.User;
import com.typhoon.spring_redis.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao userDao;

	@Cacheable(value="common",key="'id_'+#id")
	public UserDto queryByPK(Long id) {
		User u = userDao.queryByPK(id);
		if(null == u)
			return null;
		UserDto dto = new UserDto();
		BeanUtils.copyProperties(u, dto);
		return dto;
	}

}
